//
//  HMComposeButton.swift
//  Weibo
//
//  Created by fuyu on 2017/7/31.
//  Copyright © 2017年 itteacher. All rights reserved.
//

import UIKit

//自定义菜单按钮
class HMComposeButton: UIButton {
    override init(frame: CGRect) {
        super.init(frame: frame)
        // 居中等比显示
        imageView?.contentMode = .center
        titleLabel?.textAlignment = .center
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //调整子控件布局
    override func layoutSubviews() {
        //必须调用
        super.layoutSubviews()
        //  执行tranform的动画的时候不能使用frame，因为frame会发送改变，需要使用bounds，系统提示了
        //  animatable. do not use frame if view is transformed since it will not correctly reflect the actual location of the view. use bounds + center instead.
        
        //设置图片大小
        imageView?.frame.size.width = self.bounds.size.width
        imageView?.frame.size.height = self.bounds.size.height
        
        //设置图片的y
        imageView?.frame.origin.y = 0
        
        titleLabel?.frame.size.width = self.bounds.size.width
        titleLabel?.frame.size.height = self.bounds.size.height - self.bounds.size.width
        //  设置label的y
        titleLabel?.frame.origin.y = self.bounds.size.width+5
        //  设置label的x
        titleLabel?.frame.origin.x = 0
        
    }

}


